package hn.sigit.view;

import java.io.Serializable;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Conversation;

@Name("sideBarHelper")
@Scope(value = ScopeType.APPLICATION)
@AutoCreate
public class SideBarHelper implements Serializable {
	private static final long serialVersionUID = 1L;

	public String navigateTo(String view) {
		return navigateTo(view, false);
	}
	
	public String navigateToNewConv(String view) {
		return navigateTo(view, true);
	}

	public String navigateTo(String view, boolean beginNewConv) {
		resetConversation(beginNewConv);
		return view;
	}
	
	private void resetConversation(boolean beginNewConv) {
		Conversation.instance().end(); //Flag this conversation for ending
		Conversation.instance().leave(); //Leave this conversation (forces new temporary converation to start
		
		if (beginNewConv)
			Conversation.instance().begin(); //Make our new temporary conversation long running
	}

}
